package com.gdwProject.smallchange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        String detail = "";
        int input = 0;
        double balance = 0;
        double money = 0;
        String note = "";
        char exit = ' ';
        Date date = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat
                ("yyyy-MM-dd HH:mm");
        do {
            Scanner scanner = new Scanner(System.in);
            System.out.println("-------------零钱通菜单--------------");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退     出");
            System.out.print("请输入菜单选项：");
            input = scanner.nextInt();
            switch (input) {
                case 1:
                    System.out.print("-------------零钱通明细--------------");
                    System.out.println(detail);
                    break;
                case 2:
                    System.out.print("请输入收益金额：");
                    money = scanner.nextDouble();
                    while (money <= 0) {
                        System.out.print("收益金额必须>0，请重新输入:");
                        money = scanner.nextDouble();
                    }
                    balance += money;
                    date = new Date();
                    simpleDateFormat.format(date);
                    detail += "\n收益入账\t+" + money + "\t"
                            + simpleDateFormat.format(date) + "\t余额:" + balance;
                    break;
                case 3:
                    System.out.print("请输入消费去向：");
                    note = scanner.next();
                    System.out.print("请输入消费金额：");
                    money = scanner.nextDouble();
                    while (money > balance) {
                        System.out.print("余额不足，请重新输入消费金额:");
                        money = scanner.nextDouble();
                    }
                    balance -= money;
                    date = new Date();
                    detail += "\n" + note + "\t-" + money + "\t"
                            + simpleDateFormat.format(date) + "\t余额:" + balance;
                    break;
                case 4:
                    System.out.println("确定要退出程序吗？(y/n)");
                    exit = scanner.next().charAt(0);
                    while (exit != 'y' && exit != 'n') {
                        System.out.print("请输入正确的格式(y/n):");
                        exit = scanner.next().charAt(0);
                    }
                    if (exit == 'n') {
                        continue;
                    }
                    System.out.println("退出程序...");

            }
        } while (input != 4 || exit == 'n');
    }
}
